home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2001 / MacHack 2001.toast / pc / The Hacks / asciishopsource / asciiShop / mainFrame.back < prev    next >
Encoding:
Text File  |  2001-06-23  |  8.3 KB  |  276 lines

  1. /** 
  2.  * mainFrame.java
  3.  *
  4.  * Title:            ASCII Shop
  5.  * Description:        The goal of this program is to provide many functionalities of photoshop, with ASCII art.
  6.  * @author            Expotech
  7.  * @version            
  8.  */
  9.  
  10. package asciiShop;
  11.  
  12. import java.awt.*;
  13. import java.awt.event.*;
  14. import java.io.*;
  15.  
  16. public class mainFrame extends java.awt.Frame {
  17.  
  18. char[][] artBuffer2;
  19. int useLength, length1, length2;
  20. int globalCount = 0;
  21. PrintWriter writeToFile;
  22. String bigString;
  23. int i, j, k;
  24. int countForOpenFile, countForOpenFileSave;
  25. FileDialog newFile;
  26. String pathToFile;
  27. String file;
  28. BufferedReader openFile;
  29. String[] artBuffer;
  30. String[][] layerBuffer;
  31.  
  32. // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
  33. // every time the form is saved. All manual changes will be overwritten.
  34. // BEGIN GENERATED CODE
  35.     // member declarations
  36.     java.awt.TextArea fileBuffer = new java.awt.TextArea();
  37.     java.awt.List layers = new java.awt.List();
  38.     java.awt.MenuBar menuBar1 = new java.awt.MenuBar();
  39.     java.awt.Menu menuFile = new java.awt.Menu();
  40.     java.awt.MenuItem menuFileOpen = new java.awt.MenuItem();
  41.     java.awt.MenuItem menuFileWriteOut = new java.awt.MenuItem();
  42.     java.awt.MenuItem menuFileQuit = new java.awt.MenuItem();
  43.     java.awt.Menu menuLayers = new java.awt.Menu();
  44.     java.awt.MenuItem menuLayersAddLayer = new java.awt.MenuItem();
  45.     java.awt.MenuItem menuLayersRemoveLayer = new java.awt.MenuItem();
  46.     java.awt.MenuItem menuLayersRedrawLayers = new java.awt.MenuItem();
  47. // END GENERATED CODE
  48.  
  49.     public mainFrame() {
  50.     }
  51.  
  52.     public void initComponents() throws Exception {
  53. // IMPORTANT: Source code between BEGIN/END comment pair will be regenerated
  54. // every time the form is saved. All manual changes will be overwritten.
  55. // BEGIN GENERATED CODE
  56.         // the following code sets the frame's initial state
  57.  
  58.         fileBuffer.setLocation(new java.awt.Point(60, 70));
  59.         fileBuffer.setVisible(true);
  60.         fileBuffer.setSize(new java.awt.Dimension(480, 360));
  61.  
  62.         layers.setLocation(new java.awt.Point(570, 270));
  63.         layers.setVisible(true);
  64.         layers.setSize(new java.awt.Dimension(130, 160));
  65.  
  66.         menuBar1.add(menuFile);
  67.         menuBar1.add(menuLayers);
  68.  
  69.         menuFile.setLabel("File");
  70.         menuFile.add(menuFileOpen);
  71.         menuFile.add(menuFileWriteOut);
  72.         menuFile.add(menuFileQuit);
  73.  
  74.         menuFileOpen.setLabel("Open");
  75.  
  76.         menuFileWriteOut.setLabel("Write Out");
  77.  
  78.         menuFileQuit.setLabel("Quit");
  79.  
  80.         menuLayers.setLabel("Layers");
  81.         menuLayers.add(menuLayersAddLayer);
  82.         menuLayers.add(menuLayersRemoveLayer);
  83.         menuLayers.add(menuLayersRedrawLayers);
  84.  
  85.         menuLayersAddLayer.setLabel("Add Layer");
  86.  
  87.         menuLayersRemoveLayer.setLabel("Remove Layer");
  88.  
  89.         menuLayersRedrawLayers.setLabel("Redraw Layers");
  90.  
  91.         setLocation(new java.awt.Point(5, 40));
  92.         setTitle("asciiShop.mainFrame");
  93.         setLayout(null);
  94.         setMenuBar(menuBar1);
  95.         setSize(new java.awt.Dimension(736, 520));
  96.         add(fileBuffer);
  97.         add(layers);
  98.  
  99.  
  100.         fileBuffer.addTextListener(new java.awt.event.TextListener() {
  101.             public void textValueChanged(java.awt.event.TextEvent e) {
  102.                 fileBufferTextValueChanged(e);
  103.             }
  104.         });
  105.         layers.addItemListener(new java.awt.event.ItemListener() {
  106.             public void itemStateChanged(java.awt.event.ItemEvent e) {
  107.                 layersItemStateChanged(e);
  108.             }
  109.         });
  110.         menuFileOpen.addActionListener(new java.awt.event.ActionListener() {
  111.             public void actionPerformed(java.awt.event.ActionEvent e) {
  112.                 menuFileOpenActionPerformed(e);
  113.             }
  114.         });
  115.         menuFileWriteOut.addActionListener(new java.awt.event.ActionListener() {
  116.             public void actionPerformed(java.awt.event.ActionEvent e) {
  117.                 menuFileWriteOutActionPerformed(e);
  118.             }
  119.         });
  120.         menuLayersAddLayer.addActionListener(new java.awt.event.ActionListener() {
  121.             public void actionPerformed(java.awt.event.ActionEvent e) {
  122.                 menuLayersAddLayerActionPerformed(e);
  123.             }
  124.         });
  125.         addWindowListener(new java.awt.event.WindowAdapter() {
  126.             public void windowClosing(java.awt.event.WindowEvent e) {
  127.                 thisWindowClosing(e);
  128.             }
  129.         });
  130.  
  131. // END GENERATED CODE
  132.     }
  133.   
  134.       private boolean mShown = false;
  135.       
  136.     public void addNotify() {
  137.         super.addNotify();
  138.         
  139.         if (mShown)
  140.             return;
  141.             
  142.         // move components to account for insets
  143.         Insets insets = getInsets();
  144.         Component[] components = getComponents();
  145.         for (int i = 0; i < components.length; i++) {
  146.             Point location = components[i].getLocation();
  147.             location.move(location.x, location.y + insets.top);
  148.             components[i].setLocation(location);
  149.         }
  150.  
  151.         mShown = true;
  152.     }
  153.  
  154.     // Close the window when the close box is clicked
  155.     void thisWindowClosing(java.awt.event.WindowEvent e) {
  156.         setVisible(false);
  157.         dispose();
  158.         System.exit(0);
  159.     }
  160.     
  161.     public void list1ItemStateChanged(java.awt.event.ItemEvent e) {
  162.     }
  163.     
  164.     public void layersItemStateChanged(java.awt.event.ItemEvent e) {
  165.     }
  166.     
  167.     public void fileBufferTextValueChanged(java.awt.event.TextEvent e) {
  168.     }
  169.     
  170.     public void menuFileOpenActionPerformed(java.awt.event.ActionEvent e) {
  171.         bigString = new String("");
  172.         countForOpenFile = 0; // To get the number of lines to use with artBuffer
  173.         newFile = new FileDialog(this, "Open File", FileDialog.LOAD); // Opens and open file dialog box
  174.         newFile.setVisible(true);
  175.         pathToFile = newFile.getDirectory();
  176.         file = newFile.getFile();
  177.         artBuffer = new String[200];
  178.         try {
  179.             System.out.println(pathToFile + file);
  180.             openFile = new BufferedReader(new FileReader(pathToFile + file));
  181.         } catch(FileNotFoundException badStuff) {
  182.             System.out.println("The file could not be found... DAMN MICROSOFT!!!");
  183.         }
  184.             try {
  185.                 while( (artBuffer[countForOpenFile] = openFile.readLine()).equals("***end***") == false)
  186.                 {
  187.                         countForOpenFile++;
  188.                 }
  189.             } catch(IOException badStuff) {
  190.                 System.out.println("HOW THE HELL DiD YOU GET THIS ERROR!?");
  191.             }
  192.         System.out.println("How many lines in the art: " + countForOpenFile);
  193.         for(i = 0; i < countForOpenFile; i++) {
  194.             bigString = bigString + artBuffer[i] + "\n";
  195.         }
  196.         fileBuffer.setText(bigString);
  197.         countForOpenFileSave = countForOpenFile;
  198.     }
  199.     
  200.     public void menuFileWriteOutActionPerformed(java.awt.event.ActionEvent e) {
  201.         newFile = new FileDialog(this, "Save File", FileDialog.SAVE);
  202.         newFile.setVisible(true);
  203.         pathToFile = newFile.getDirectory();
  204.         file = newFile.getFile();
  205.         try {
  206.         writeToFile = new PrintWriter(new FileWriter(pathToFile + file), true);
  207.         System.out.println("Wrote to file: " + pathToFile + file);
  208.         } catch(IOException badStuff) {
  209.             System.out.println("GODDAMN HOW THE HELL DID YOU MANAGE TO GET THIS ERROR!?");
  210.         }
  211.         bigString = fileBuffer.getText();
  212.         writeToFile.println(bigString + "\n***end***");
  213.         System.out.println("Wrote out to file: " + pathToFile + file + "\n" + bigString + "***end***");
  214.         return;
  215.     }
  216.     
  217.     public void menuLayersAddLayerActionPerformed(java.awt.event.ActionEvent e) {
  218.         layerBuffer = new String[globalCount][];
  219.         globalCount++;
  220.         bigString = new String("");
  221.         countForOpenFile = 0; // To get the number of lines to use with artBuffer
  222.         newFile = new FileDialog(this, "Add Layer", FileDialog.LOAD); // Opens and open file dialog box
  223.         newFile.setVisible(true);
  224.         pathToFile = newFile.getDirectory();
  225.         file = newFile.getFile();
  226.         layerBuffer[globalCount] = new String[200];
  227.             System.out.println("Trying to apply layer: " + pathToFile + file);
  228.             try {
  229.                 openFile = new BufferedReader(new FileReader(pathToFile + file));
  230.             } catch(IOException badStuff) {
  231.                 System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? - 3");
  232.             }
  233.             try {
  234.                 while( (layerBuffer[globalCount][countForOpenFile] = openFile.readLine()).equals("***end***") == false)
  235.                 {
  236.                         countForOpenFile++;
  237.                 }
  238.             } catch(IOException badStuff) {
  239.                 System.out.println("HOW THE HELL DID YOU GET THIS ERROR!? -2");
  240.             }
  241.             length1 = artBuffer[0].length();
  242.             length2 = layerBuffer[globalCount][0].length();
  243.             if(length1 < length2) {
  244.                 useLength = length2;
  245.             }
  246.             else {
  247.                 useLength = length1;
  248.             }
  249.             
  250.             artBuffer2 = new char[countForOpenFile][useLength];
  251.             
  252.             for(i = 0; i < countForOpenFileSave; i++) {
  253.                 for(k = 0; k < useLength; k++) {
  254.                     artBuffer2[i][k] = artBuffer[i].charAt(k);
  255.                 }
  256.                 for(j = 0; j < useLengthl j++) {
  257.                     if(artBuffer[i].charAt(j) != ' ') {
  258.                         artBuffer2[i][j] = artBuffer[i].charAt(j);
  259.                     }
  260.                     else {
  261.                         artBuffer2[i][j] = ' ';
  262.                     }
  263.                 }    
  264.             }
  265.             for(i = 0; i < countForOpenfileSave; i++) {
  266.                 for(k = 0; k < useLength; k++) {
  267.                     System.out.println(artBuffer2[i][k];
  268.                 }
  269.             }
  270.     }
  271.     
  272.     /*layerBuffer = new String[globalCount][];
  273.     layerBuffer[2] = new String[2]{"blah","soo"};
  274.     system.out.println(layerBuffer[2][1])*/
  275. }
  276.